package com.usian.common.config;


import com.usian.model.media.pojos.WmUser;
import com.usian.utils.threadlocal.WmThreadLocalUtils;
import org.springframework.core.annotation.Order;
import org.springframework.web.filter.GenericFilterBean;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@Order(2)
@WebFilter(filterName = "WemediatuFilter",urlPatterns = "/*")
public class WemediatuFilter extends GenericFilterBean {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletResponse response=(HttpServletResponse) servletResponse;
        HttpServletRequest request=(HttpServletRequest) servletRequest;
        String userId = request.getHeader("userId");
        if (userId!=null){
            WmUser wm=new WmUser();
            wm.setApUserId(Integer.valueOf(userId));
            WmThreadLocalUtils.setUser(wm);
        }
        filterChain.doFilter(request,response);

    }
}
